package com.alstudio.utils.notification;

import java.util.ArrayList;

import com.alstudio.utils.log.Mylog;

public class NoticeItemManager {

	private final String TAG = "NoticeItemManager";

	private ArrayList<NoticeItem> itemList = new ArrayList<NoticeItem>();

	private NoticeItemManagerListener mListener;

	public void setNoticeItemManager(NoticeItemManagerListener listener) {
		mListener = listener;
	}

	public synchronized void removeNoticeItem() {
		synchronized (itemList) {
			if (itemList.size() > 0) {
				NoticeItem item = itemList.get(0);
				itemList.remove(0);

				if (mListener != null) {
					mListener.onNoticeItemRemoved(item);
				}
			}

			if (itemList.size() == 0) {
				if (mListener != null) {
					mListener.onNoticeItemListEmpty();
				}
				Mylog.d("notice list empty!");
			}
		}
	}

	public synchronized void addNoticeItem(NoticeItem item) {
		synchronized (itemList) {
			Mylog.d("new notice item added!type:" + item.getType());
			itemList.add(item);
			if (mListener != null) {
				mListener.onNewNoticeItemAdded(item);
			}
		}
	}

	public synchronized NoticeItem getCurrentNoticeItem() {
		synchronized (itemList) {
			NoticeItem item = null;
			if (itemList.size() > 0) {
				item = itemList.get(0);
			} else {
				Mylog.d("no next notice item!");
			}
			return item;
		}
	}

	public synchronized NoticeItem getNextNoticeItem() {
		synchronized (itemList) {
			NoticeItem item = null;
			if (itemList.size() > 0) {
				item = itemList.get(0);
			} else {
				Mylog.d("no next notice item!");
			}
			return item;
		}
	}

}
